﻿#define _CRT_SECURE_NO_WARNINGS
#include"RBTree.h"
#include"AVLTree.h"
void TestRBTree1()
{
	RBTree<int, int> t;
	// 常规的测试⽤例
	int a[] = { 16, 3, 7, 11, 9, 26, 18, 14, 15 };
	int b[] = { 16, 3, 27, 1, 93, 46, 8, 24, 15 };
	for (auto e : b)
	{
		t.Insert({ e, e });
	}
	t._Inorder();
	cout << endl;
	cout << t.CheckRoot() << endl;
	cout << t._Check_Have_Continuous_Red() << endl;
	cout << t._Check_Is_Same_BlackNum() << endl;

}
// 插⼊⼀堆随机值，测试平衡，顺便测试⼀下⾼度和性能等
void TestRBTree2()
{
	const int N = 100;
	vector<int> v;
	v.reserve(N);
	srand(time(0));
	for (size_t i = 0; i < N; i++)
	{
		v.push_back(rand() + i);
	}
	size_t begin2 = clock();
	RBTree<int, int> t;
	for (auto e : v)
	{
		t.Insert(make_pair(e, e));
	}
	size_t end2 = clock();
	cout << "Insert:" << end2 - begin2 << endl;
	cout << t.CheckRoot() << endl;
	cout << t._Check_Have_Continuous_Red() << endl;
	cout << t._Check_Is_Same_BlackNum() << endl;
}

//比较AVLTree和RBTree
void  TestCompare() {
	const int N = 10000;
	srand(time(0));
	vector<int> v;
	v.reserve(N);
	RBTree<int, int> rbt;
	AVLTree<int, int> avlt;

	for (int i = 0; i < N; i++) {
		v.push_back(rand() + i);
	}

	size_t begin1 = clock();
	for (auto& num : v) {
		avlt.Insert({ num,num });
	}
	size_t begin2 = clock();
	size_t begin11 = clock();
	for (auto& num : v) {
		rbt.Insert({ num,num });
	}
	size_t begin22 = clock();
	cout << "AVLTree insert：" << begin2 - begin1 << endl;
	cout << "RBTree insert：" << begin22 - begin11 << endl;

	cout <<"AVLTree IsBalanceTree："<< avlt.IsBalanceTree() << endl;
	cout << "RBTree IsStandardRBTree：" << rbt._Check_Have_Continuous_Red() << endl;
	cout << "RBTree IsStandardRBTree：" << rbt._Check_Is_Same_BlackNum() << endl;
	cout <<"AVLTree Size："<< avlt.Size() << endl;
	cout << "RBTree Size：" << rbt.Size() << endl;
	cout << "AVLTree Heights：" << avlt.Height()<< endl;
	cout << "RBTree Heights：" << rbt.Height()<< endl;

}
int main() {
	//TestRBTree1();
	//TestRBTree2();
	TestCompare();
	return 0;
}